/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;
import Connection.DataAccess;
import Controller.KhachHangController;
import Model.KhachHang;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 * @author My PC
 */
public class JFrameKhachHang extends javax.swing.JFrame {

    /**
     * Creates new form JFrameKhachHang
     */
    public JFrameKhachHang() {
        initComponents();
         LoadTable();
    }

    KhachHang kh = new KhachHang();
    KhachHangController khcontroller = new KhachHangController();
      public void GetInfo()
    {
        kh.setMaKhachhang(txtMaKH.getText().toString());
        kh.setTenKhachhang(txtHoTen.getText().toString());
        kh.setNgaysinh(convertJavaDateToSqlDate(this.jNgaysinh.getDate()));
        kh.setGioitinh(cboGioiTinh.getSelectedItem().toString());
        kh.setLoaikh(txtLoaiKH.getText().toString());
        kh.setDiachi(txtDiaChi2.getText().toString());
        kh.setDienthoai(txtSDT.getText().toString());
        kh.setSocmnd(txtSocmnd.getText().toString());
        kh.setEmail(txtEMail.getText().toString());
        kh.setNgaymua(convertJavaDateToSqlDate(this.jNgaymua.getDate()));
    }
      
       public java.sql.Date convertJavaDateToSqlDate(java.util.Date date) {
        return new java.sql.Date(date.getTime());
    }

    public java.util.Date convertJavaSqlToDate(java.sql.Date date) {
        return new java.util.Date(date.getTime());
    }
    public void LoadTable()
    {
        DataAccess da = new DataAccess();
        String sql = "select MA_KHACHHANG,TEN_KHACHHANG,NGAYSINH,DIACHI,"
                + "LOAI_KHACHHANG,GIOITINH,SO_CMND,DIENTHOAI,EMAIL,"
                + "NGAY_MUA from tblKhachHang";
        da.ShowInfor(sql,tblUpdateCus);
    }
    

     private void Setcontrol(Boolean edit) {

        this.txtMaKH.setEnabled(edit);
        this.txtHoTen.setEnabled(edit);
        this.txtLoaiKH.setEnabled(edit);
        this.jNgaysinh.setEnabled(edit);
        this.cboGioiTinh.setEnabled(edit);
        this.txtDiaChi2.setEnabled(edit);
        this.txtSDT.setEnabled(edit);        
        this.txtSocmnd.setEnabled(edit);
        this.txtEMail.setEnabled(edit);
        this.jNgaymua.setEnabled(edit);
//        
//        this.btnTimKiem.setEnabled(!edit);  
//        this.btnThem.setEnabled(!edit);
//        this.btnSua.setEnabled(!edit);
//        this.btnXoa.setEnabled(!edit);
//        this.btnLuu.setEnabled(!edit);
//        this.btnThoat.setEnabled(!edit);
    }

    private void AddItem() {
       String[] st = {"Nữ","Nam"};
        for(int i=0;i<st.length;i++)
        {
            cboGioiTinh.addItem(st[i]);
        }
   }
   
    private void XoaText() {
        this.txtMaKH.setText("");
        this.txtHoTen.setText("");
       // this.jNgaysinh.;
        this.txtLoaiKH.setText("");
        this.txtDiaChi2.setText("");
        this.txtSDT.setText("");
        this.txtSocmnd.setText("");
        this.txtEMail.setText("");
        //this.cboGioiTinh.removeAllItems();
     //   AddItem();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtHoTen = new javax.swing.JTextField();
        txtLoaiKH = new javax.swing.JTextField();
        txtMaKH = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtDiaChi2 = new javax.swing.JTextField();
        jNgaysinh = new com.toedter.calendar.JDateChooser();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cboGioiTinh = new javax.swing.JComboBox();
        txtSocmnd = new javax.swing.JTextField();
        txtSDT = new javax.swing.JTextField();
        txtEMail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jNgaymua = new com.toedter.calendar.JDateChooser();
        jPanel4 = new javax.swing.JPanel();
        btnThem = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnCapNhat = new javax.swing.JButton();
        btnTimKiemMa = new javax.swing.JButton();
        btnThoat = new javax.swing.JButton();
        btnTimKiemTen = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblUpdateCus = new javax.swing.JTable();

        jPanel1.setBackground(new java.awt.Color(0, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cập nhật thông tin khách hàng", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBackground(new java.awt.Color(0, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 274));

        jLabel1.setText("Mã khách hàng");

        jLabel2.setText("Họ và tên");

        jLabel3.setText("Ngày sinh");

        jLabel4.setText("Địa chỉ");

        txtHoTen.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        txtLoaiKH.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        txtMaKH.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jLabel9.setText("Loại khách hàng ");

        txtDiaChi2.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3))))
                        .addGap(12, 12, 12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(20, 20, 20)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtDiaChi2, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addComponent(txtHoTen, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtMaKH)
                    .addComponent(txtLoaiKH)
                    .addComponent(jNgaysinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMaKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jNgaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(txtDiaChi2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLoaiKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 41;
        gridBagConstraints.ipady = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(61, 12, 0, 0);
        jPanel1.add(jPanel2, gridBagConstraints);

        jPanel3.setBackground(new java.awt.Color(0, 255, 255));

        jLabel5.setText("Giới tính");

        jLabel6.setText("Số CMND");

        jLabel7.setText("Số điện thoại");

        jLabel8.setText("Email (nếu có)");

        cboGioiTinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nữ", "Nam" }));

        txtSocmnd.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        txtSDT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        txtEMail.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        jLabel10.setText("Ngày mua hàng ");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtSDT, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(txtEMail)
                    .addComponent(txtSocmnd)
                    .addComponent(cboGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jNgaymua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(30, 30, 30))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cboGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtSocmnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10)
                    .addComponent(jNgaymua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 18;
        gridBagConstraints.ipady = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(61, 119, 0, 0);
        jPanel1.add(jPanel3, gridBagConstraints);

        jPanel4.setBackground(new java.awt.Color(0, 255, 255));

        btnThem.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/add 16x16.png"))); // NOI18N
        btnThem.setText("Thêm ");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnSua.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/edit (3).png"))); // NOI18N
        btnSua.setText("Sửa");
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnXoa.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/delete (3).png"))); // NOI18N
        btnXoa.setText("Xóa");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnCapNhat.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnCapNhat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Reset.png"))); // NOI18N
        btnCapNhat.setText("Cập Nhật");
        btnCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapNhatActionPerformed(evt);
            }
        });

        btnTimKiemMa.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnTimKiemMa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Search (3).png"))); // NOI18N
        btnTimKiemMa.setText("Tìm kiếm_Mã");
        btnTimKiemMa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTimKiemMaActionPerformed(evt);
            }
        });

        btnThoat.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnThoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Exit.png"))); // NOI18N
        btnThoat.setText("Thoát");
        btnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatActionPerformed(evt);
            }
        });

        btnTimKiemTen.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btnTimKiemTen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Search (3).png"))); // NOI18N
        btnTimKiemTen.setText("Tìm kiếm_Tên");
        btnTimKiemTen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTimKiemTenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnThem, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                .addGap(38, 38, 38)
                .addComponent(btnSua)
                .addGap(40, 40, 40)
                .addComponent(btnXoa)
                .addGap(29, 29, 29)
                .addComponent(btnCapNhat)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnTimKiemMa)
                .addGap(18, 18, 18)
                .addComponent(btnTimKiemTen)
                .addGap(18, 18, 18)
                .addComponent(btnThoat)
                .addGap(86, 86, 86))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThem)
                    .addComponent(btnSua)
                    .addComponent(btnXoa)
                    .addComponent(btnCapNhat)
                    .addComponent(btnTimKiemMa)
                    .addComponent(btnThoat)
                    .addComponent(btnTimKiemTen))
                .addContainerGap())
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 19;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 39, 0, 0);
        jPanel1.add(jPanel4, gridBagConstraints);

        tblUpdateCus.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tblUpdateCus.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã KH", "Họ và tên", "Ngày sinh", "Địa chỉ", "Loại KH", "Giới tính", "Số CMND", "Số điện thoại", "Email()", "Ngày mua"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tblUpdateCus.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblUpdateCusMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblUpdateCus);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 919;
        gridBagConstraints.ipady = 531;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(11, 12, 7, 0);
        jPanel1.add(jScrollPane1, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1060, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 581, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
        if(txtMaKH.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this,"Bạn phải nhập mã khách hàng");
        }
        else
        {
            GetInfo();
            if(KhachHangController.ThemKH(kh)){
                JOptionPane.showMessageDialog(this, "Them khach hang thanh cong");
            }
            else{
                JOptionPane.showMessageDialog(this,"Them khach hang that bai");
            }
            LoadTable();
        }
    }//GEN-LAST:event_btnThemActionPerformed

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        // TODO add your handling code here:
        GetInfo();
        if(KhachHangController.SuaKH(kh))
        {
            JOptionPane.showMessageDialog(this,"Sửa khách hàng thành công");
            LoadTable();
        }
        else
        JOptionPane.showMessageDialog(this,"Sửa khách hàng không hành công");
        LoadTable();
    }//GEN-LAST:event_btnSuaActionPerformed

    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        // TODO add your handling code here:
        GetInfo();
        if(KhachHangController.XoaKH(kh)==false)
        JOptionPane.showMessageDialog(this,"Không xoá được mã khách hàng vì tồn tại hoá đơn thuộc khách hàng này");

        LoadTable();
    }//GEN-LAST:event_btnXoaActionPerformed

    private void btnCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapNhatActionPerformed
        LoadTable();
    }//GEN-LAST:event_btnCapNhatActionPerformed

    private void btnTimKiemMaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTimKiemMaActionPerformed
        // TODO add your handling code here:
        String sql = "select MA_KHACHHANG,TEN_KHACHHANG,NGAYSINH,DIACHI,"
        + "LOAI_KHACHHANG,GIOITINH,SO_CMND,DIENTHOAI,EMAIL,"
        + "NGAY_MUA from tblKhachHang where MA_KHACHHANG like N'%"+txtMaKH.getText()+"%'";
        DataAccess da = new DataAccess();
        da.ShowInfor(sql, tblUpdateCus);
    }//GEN-LAST:event_btnTimKiemMaActionPerformed

    private void btnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatActionPerformed
        // TODO add your handling code here:
        jPanel1.setVisible(false);
    }//GEN-LAST:event_btnThoatActionPerformed

    private void btnTimKiemTenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTimKiemTenActionPerformed
        // TODO add your handling code here:
        String sql = "select MA_KHACHHANG,TEN_KHACHHANG,NGAYSINH,DIACHI,"
        + "LOAI_KHACHHANG,GIOITINH,SO_CMND,DIENTHOAI,EMAIL,"
        + "NGAY_MUA from tblKhachHang where TEN_KHACHHANG like N'%"+txtHoTen.getText()+"%'";
        DataAccess da = new DataAccess();
        da.ShowInfor(sql, tblUpdateCus);
    }//GEN-LAST:event_btnTimKiemTenActionPerformed

    private void tblUpdateCusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblUpdateCusMouseClicked
        // TODO add your handling code here:
        int dong=tblUpdateCus.getSelectedRow();
        txtMaKH.setText((String)this.tblUpdateCus.getValueAt(dong,0));
        txtLoaiKH.setText((String)tblUpdateCus.getValueAt(dong,4));
        txtHoTen.setText((String)tblUpdateCus.getValueAt(dong,1));
        cboGioiTinh.setSelectedItem((String)tblUpdateCus.getValueAt(dong,5));
        //        jNgaysinh.setDate((Date)tblUpdateCus.getValueAt(dong,2));
        String pattern = "yyyy-MM-dd";
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = format.parse(this.tblUpdateCus.getValueAt(dong, 2).toString());
        } catch (ParseException ex) {
            Logger.getLogger(JFrameKhachHang.class.getName()).log(Level.SEVERE, null, ex);
        }
        jNgaysinh.setDate(date);
        txtDiaChi2.setText((String)tblUpdateCus.getValueAt(dong,3));
        txtSocmnd.setText((String)tblUpdateCus.getValueAt(dong, 6));
        txtSDT.setText((String)tblUpdateCus.getValueAt(dong,7));
        txtEMail.setText((String)tblUpdateCus.getValueAt(dong,8));
        //   jNgaymua.setDate((Date)tblUpdateCus.getValueAt(dong,9));
        Date date1 = null;
        try {
            date1 = format.parse(this.tblUpdateCus.getValueAt(dong, 9).toString());
        } catch (ParseException ex) {
            Logger.getLogger(JFrameKhachHang.class.getName()).log(Level.SEVERE, null, ex);
        }
        jNgaymua.setDate(date1);
    }//GEN-LAST:event_tblUpdateCusMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFrameKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFrameKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFrameKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFrameKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrameKhachHang().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCapNhat;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnThoat;
    private javax.swing.JButton btnTimKiemMa;
    private javax.swing.JButton btnTimKiemTen;
    private javax.swing.JButton btnXoa;
    private javax.swing.JComboBox cboGioiTinh;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private com.toedter.calendar.JDateChooser jNgaymua;
    private com.toedter.calendar.JDateChooser jNgaysinh;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblUpdateCus;
    private javax.swing.JTextField txtDiaChi2;
    private javax.swing.JTextField txtEMail;
    private javax.swing.JTextField txtHoTen;
    private javax.swing.JTextField txtLoaiKH;
    private javax.swing.JTextField txtMaKH;
    private javax.swing.JTextField txtSDT;
    private javax.swing.JTextField txtSocmnd;
    // End of variables declaration//GEN-END:variables
}
